<?php
	session_start();
	require('include/inc.start.php');

   require("include/connectionParameters.php");
   
         $connection = mysql_connect($host,$user,$pass)
		or die ("Can't connect to server, try again later, please");

	mysql_select_db($database);
   
// show all books by default
	$query = "select Books.BookId, Books.Title, Books.Author, Books.ISBN, Books.Edition, Books.Course, Books.Professor, Books.Location, Books.Price, Books.PostDate from Books, Hits where Books.BookId=Hits.BookId order by Hits.HitCount desc limit 6;";
	$result = mysql_query($query,$connection)
		or die ("Problem with reading data from database, try again later.");
		
		while( $row = mysql_fetch_row($result )){
			// get data from database
			$bookId = $row[0];
			$title = $row[1];
			$author = $row[2];
			$isbn = $row[3];
			$edition = $row[4];
			$course = $row[5];
			$professor = $row[6];
			$location = $row[7];
			$price = $row[8];
			$postDate = $row[9];
			
			// extract data in YYYY-MM-DD format
			$dateData = explode("-",$postDate);
			$year = $dateData[0];
			$month = $dateData[1];
			$day = $dateData[2];
			
			// converting to format "Wednesday, August 05, 2009"
			$labelData = date("l,F d,Y", mktime(0,0,0,$month, $day, $year));
			$bookLink = $title.",".$author.",".$edition." - ".$price."(".$location.")";
			
			echo "<li><a href='bookDetails.php?bookId='".$bookId.">".$bookLink."</a> </li>";
			}
			
			mysql_close($connection);
			?>